import time
from datetime import datetime
from info import db


class Input(db.Model):
    __tablename__ = "DATA_INPUT"
    Id = db.Column(db.Integer, primary_key=True, autoincrement=True, unique=True)  # 编号
    Factory_name = db.Column(db.Integer, nullable=False, default=0)  # 选择纺织厂
    Cotton_variety_count = db.Column(db.Integer, nullable=False, default=10)  # 棉花种类数量
    Yarn_count = (db.Column(db.Float(2), nullable=False))  # 纱线支数
    Yarn_strength = (db.Column(db.Float(2), nullable=False))  # 纱线强度
    Actual_twist = (db.Column(db.Float(2), nullable=False))  # 实际捻度
    Actual_twist_factor = (db.Column(db.Float(2), nullable=False))  # 实际捻系数
    Twisting_efficiency = (db.Column(db.Float(2), nullable=False))  # 加捻效率
    Combed_combed = (db.Column(db.Float(1), nullable=False, default=0.1))  # 精梳(J)0.5/普梳(C)0.1
    Knitting_yarn = (db.Column(db.Boolean, default=False))  # 是否针织纱(K)
    Sirospun = (db.Column(db.Boolean, default=False))  # 是否赛络纺(S)
    Compact_spinning = (db.Column(db.Boolean, default=False))  # 是否紧密纺(F)
    Key = db.Column(db.String(128), nullable=True)  # 权限验证
    Create_time = db.Column(db.DateTime, default=datetime.now)  # 创建时间

    def to_dict(self):  # 将模型中的数据转存到了字典中, 并且封装了数据的判断和格式转换
        resp_dict = {
            'Id': self.Id,
            'Factory_name': self.Factory_name,
            "Cotton_variety_count": self.Cotton_variety_count,
            'Yarn_count': self.Yarn_count,
            'Yarn_strength': self.Yarn_strength,
            'Actual_twist': self.Actual_twist,
            'Actual_twist_factor': self.Actual_twist_factor,
            'Twisting_efficiency': self.Twisting_efficiency,
            'Combed_combed': self.Combed_combed,
            'Knitting_yarn': self.Knitting_yarn,
            'Sirospun': self.Sirospun,
            'Compact_spinning': self.Compact_spinning,
            'Key': self.Key,
            'Create_time': self.Create_time,
        }
        return resp_dict


class Outputgroup(db.Model):
    __tablename__ = "OUT_PUT_GROUP"
    Id = db.Column(db.Integer, primary_key=True, autoincrement=True, unique=True)  # 编号
    User = db.Column(db.String(50), nullable=False)  # 当前用户
    Craft = db.Column(db.String(50), nullable=False)  # 当前工艺
    Final_calculation_time = db.Column(db.String(50), nullable=False)  # 最后计算时间
    Group_id = db.Column(db.Integer, default=0)

    # def __repr__(self):
    #     return '<Outputgroup %r>' % self.Group_id

    def to_dict(self):  # 将模型中的数据转存到了字典中, 并且封装了数据的判断和格式转换
        resp_dict = {
            'Id': self.Id,
            'User': self.User,
            "Craft": self.Craft,
            "Final_calculation_time": self.Final_calculation_time,
            "Group": self.Group,
        }
        return resp_dict


class Getoutput(db.Model):
    __tablename__ = "GET_OUT_PUT"
    Id = db.Column(db.Integer, primary_key=True, autoincrement=True, unique=True)  # 编号
    Scale_factor = db.Column(db.Float(4), nullable=False)  # 比例系数
    Batch_number = db.Column(db.String(50), nullable=False)  # 内部批号
    Production_place = db.Column(db.String(50), nullable=False)  # 产地
    Micronaire = db.Column(db.Float(2), nullable=False)  # 马克隆值
    Average_length = db.Column(db.Float(2), nullable=False)  # 平均长度
    Fibre_strength = db.Column(db.Float(2), nullable=False)  # 断裂比强度
    Moisture_regain = db.Column(db.Float(2), nullable=False)  # 回潮率
    Trash_content = db.Column(db.Float(2), nullable=False)  # 含杂率
    Spinning_coefficient = db.Column(db.Float(2), nullable=False)  # 可纺系数
    Maturity = db.Column(db.Float(2), nullable=False)  # 成熟度
    Uniformity = db.Column(db.Float(2), nullable=False)  # 整齐度
    Fiber_index = db.Column(db.Float(2), nullable=False)  # 短纤指数
    Reflectivity = db.Column(db.Float(2), nullable=False)  # 反射率
    Yellowness_index = db.Column(db.Float(2), nullable=False)  # 黄度
    Neps = db.Column(db.Float(2), nullable=False)  # 棉结
    Group_id = db.Column(db.Integer, default=0)  # 编号

    def to_dict(self):  # 将模型中的数据转存到了字典中, 并且封装了数据的判断和格式转换
        resp_dict = {
            'Id': self.Id,
            'Batch_number': self.Batch_number,
            "Production_place": self.Production_place,
            'Micronaire': self.Micronaire,
            'Moisture_regain': self.Moisture_regain,
            'Trash_content': self.Trash_content,
            'Spinning_coefficient': self.Spinning_coefficient,
            'Maturity': self.Maturity,
            'Uniformity': self.Uniformity,
            'Fiber_index': self.Fiber_index,
            'Reflectivity': self.Reflectivity,
            'Yellowness_index': self.Yellowness_index,
            'Neps': self.Neps,
        }
        return resp_dict
